

//--------------------------------------------------------------------------------------
// Vertex and pixel shaders for font rendering
// Please note the removal of comment or dead lines...
// They are commented out because the shader compiler has no use for them.
//--------------------------------------------------------------------------------------
static const char g_strFontShader[] =
"struct VS_IN\n"
"{\n"
	"float2 Pos : POSITION;\n"
	"float2 Tex : TEXCOORD0;\n"
	"float4 ChannelSelector : COLOR0;\n"
"};\n"
        //  "\n"
"struct VS_OUT\n"
"{\n"
"float4 Position : POSITION;\n"
"float4 Diffuse : COLOR0;\n"
"float2 TexCoord0 : TEXCOORD0;\n"
"float4 ChannelSelector : COLOR1;\n"
"};\n"
//  "\n"
"uniform float4 Color : register(c1);\n"
"uniform float2 TexScale : register(c2);\n"
"uniform float2 ScreenScale : register(c3);\n"
//  "\n"
"sampler FontTexture : register(s0);\n"
//  "\n"
"VS_OUT FontVertexShader( centroid VS_IN In )\n"
"{\n"
	"VS_OUT Out;\n"
	"Out.Position.x  = (In.Pos.x-0.5);\n"
	"Out.Position.y  = (In.Pos.y-0.5);\n"
	// Convert to screen pos
	"Out.Position.xy *= ScreenScale.xy;\n"
	"Out.Position.z  = ( 0.0 );\n"
	"Out.Position.w  = ( 1.0 );\n"
	"Out.Diffuse = Color;\n"
	"Out.TexCoord0.x = In.Tex.x * TexScale.x;\n"
	"Out.TexCoord0.y = In.Tex.y * TexScale.y;\n"
	"Out.ChannelSelector = In.ChannelSelector;\n"
	"return Out;\n"
	"}\n"
	// "\n"
	"float4 FontPixelShader( VS_OUT In ) : COLOR0\n"
	"{\n"
	//      "// Fetch a texel from the font texture\n"
	"float4 FontTexel = tex2D( FontTexture, In.TexCoord0 );\n"
	//      "\n"
	"if( dot( In.ChannelSelector, float4(1,1,1,1) ) )\n"
	"{\n"
		//          "// Select the color from the channel\n"
		"float value = dot( FontTexel, In.ChannelSelector );\n"
		//          "\n"
		//          "// For white pixels, the high bit is 1 and the low\n"
		//          "// bits are luminance, so r0.a will be > 0.5. For the\n"
		//          "// RGB channel, we want to lop off the msb and shift\n"
		//          "// the lower bits up one bit. This is simple to do\n"
		//          "// with the _bx2 modifier. Since these pixels are\n"
		//          "// opaque, we emit a 1 for the alpha channel (which\n"
		//          "// is 0.5 x2 ).\n"
		//          "\n"
		//          "// For black pixels, the high bit is 0 and the low\n"
		//          "// bits are alpha, so r0.a will be < 0.5. For the RGB\n"
		//          "// channel, we emit zero. For the alpha channel, we\n"
		//          "// just use the x2 modifier to scale up the low bits\n"
		//          "// of the alpha.\n"
		"float4 Color;\n"
		"Color.rgb = ( value > 0.5f ? 2*value-1 : 0.0f );\n"
		"Color.a = 2 * ( value > 0.5f ? 1.0f : value );\n"
		//          "\n"
		//          "// Return the texture color modulated with the vertex\n"
		//          "// color\n"
		"return Color * In.Diffuse;\n"
	"}\n"
	"else\n"
	"{\n"
		"return FontTexel * In.Diffuse;\n"
	"}\n"
"}\n";

